package cn.rengy.web.framework.wxmp.component.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.rengy.tpa.wxmp.component.auth.ComponentAuthManager;
import cn.rengy.web.framework.property.service.PropertyService;
import cn.rengy.web.framework.wxmp.component.token.ComponentTokenService;

@Service
public class ComponentAuthService {
	//private static Logger logger = LoggerFactory.getLogger(ComponentAuthService.class);
	@Autowired
	private ComponentTokenService componentTokenService;
	@Autowired
	private PropertyService propertiesService;
	
	/**
	 * 移动端访问授权
	 * @return
	 * @throws Exception 
	 */
	public String getWxAuthURL() throws Exception{
		String component_appid=propertiesService.getProperty("DEFAULT_COMPONENT_APPID");
		String pre_auth_code=componentTokenService.preAuthCode(component_appid);
		String redirectURL=propertiesService.getProperty("domain")+"/wxtp/authSuccess/"+component_appid;
		String url=ComponentAuthManager.generateWxAuthURI(component_appid, pre_auth_code, redirectURL, 3);
		return url;
	}
	/**
	 * PC端授权扫码授权
	 * @return
	 * @throws Exception
	 */
	public String getPcAuthURL() throws Exception{
		String component_appid=propertiesService.getProperty("DEFAULT_COMPONENT_APPID");
		String pre_auth_code=componentTokenService.preAuthCode(component_appid);
		String redirectURL=propertiesService.getProperty("domain")+"/wxtp/authSuccess/"+component_appid;
		String url=ComponentAuthManager.generatePcAuthURI(component_appid, pre_auth_code, redirectURL, 3);
		return url;
	}
}
